<!DOCTYPE html>

<html xmlns:th="http://www.w3.org/1999/xhtml">

<head>

    <!-- 页面meta -->

    <meta charset="utf-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <title>微服务单点登录系统</title>

    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">

    <!-- 引入 Vue.js，使用国内的 CDN -->
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.14/vue.min.js"></script>
    <!-- 引入 Element UI，使用国内的 CDN -->
    <script src="https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.7/index.min.js"></script>
    <!-- 引入 Element UI 样式，使用国内的 CDN -->
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.7/theme-chalk/index.min.css">
    <!-- 引入 axios，使用国内的 CDN -->
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.4/axios.min.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>





</head>

<body class="hold-transition">

<div id="app">

    <div class="content-header">

        <h1>微服务单点登录系统</h1>

    </div>

    <div class="app-container">

        <div class="box">

            <div class="filter-container">
                <el-input placeholder="账户名" v-model="pagination.login_name"  style="width: 200px;" class="filter-item"></el-input>
                <el-button @click="getAll()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>

            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>

                <el-table-column type="index" align="center" label="序号"></el-table-column>

                <el-table-column prop="login_name" label="账户名" align="center"></el-table-column>

                <el-table-column prop="password" label="密码" align="center"></el-table-column>

                <el-table-column prop="name" label="名字" align="center"></el-table-column>

                <el-table-column prop="phone" label="手机号" align="center"></el-table-column>

                <el-table-column prop="emile" label="邮箱" align="center"></el-table-column>

                <el-table-column prop="creat_time" label="创建时间" align="center"></el-table-column>

                <el-table-column prop="modify_time" label="修改时间" align="center"></el-table-column>

                <el-table-column label="操作" align="center">

                    <template slot-scope="scope">

                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>

                        <el-button type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>

                    </template>

                </el-table-column>

            </el-table>


            <!-- 新增标签弹层 -->

            <div class="add-form">

                <el-dialog title="新增账户" :visible.sync="dialogFormVisible">

                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">

                        <el-row>

                            <el-col :span="12">

                                <el-form-item label="账户名" prop="login_name">

                                    <el-input v-model="formData.login_name"/>

                                </el-form-item>

                            </el-col>

                            <el-col :span="12">

                                <el-form-item label="密码" prop="password">

                                    <el-input v-model="formData.password"/>

                                </el-form-item>

                            </el-col>

                            <el-col :span="12">

                                <el-form-item label="名字" prop="name">

                                    <el-input v-model="formData.name"/>

                                </el-form-item>

                            </el-col>

                            <el-col :span="12">

                                <el-form-item label="手机号" prop="phone">

                                    <el-input v-model="formData.phone"/>

                                </el-form-item>

                            </el-col>

                            <el-col :span="12">

                                <el-form-item label="邮箱" prop="emile">

                                    <el-input v-model="formData.emile"/>

                                </el-form-item>

                            </el-col>

                        </el-row>

                    </el-form>

                    <div slot="footer" class="dialog-footer">

                        <el-button @click="cancel()">取消</el-button>

                        <el-button type="primary" @click="handleAdd()">确定</el-button>

                    </div>

                </el-dialog>

            </div>


            <!-- 编辑标签弹层 -->

            <div class="add-form">

                <el-dialog title="编辑检查项" :visible.sync="dialogFormVisible4Edit">

                    <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right" label-width="100px">

                        <el-row>

                            <el-col :span="12">

                                <el-form-item label="修改账户名" prop="login_name">

                                    <el-input v-model="formData.login_name"/>

                                </el-form-item>

                            </el-col>

                            <el-col :span="12">

                                <el-form-item label="修改密码" prop="password">

                                    <el-input v-model="formData.password"/>

                                </el-form-item>

                            </el-col>

                            <el-col :span="12">

                                <el-form-item label="修改名字" prop="name">

                                    <el-input v-model="formData.name"/>

                                </el-form-item>

                            </el-col>

                            <el-col :span="12">

                                <el-form-item label="修改电话号" prop="phone">

                                    <el-input v-model="formData.phone"/>

                                </el-form-item>

                            </el-col>

                            <el-col :span="12">

                                <el-form-item label="修改邮箱" prop="emile">

                                    <el-input v-model="formData.emile"/>

                                </el-form-item>

                            </el-col>

                        </el-row>

                    </el-form>

                    <div slot="footer" class="dialog-footer">

                        <el-button @click="cancel()">取消</el-button>

                        <el-button type="primary" @click="handleEdit()">确定</el-button>

                    </div>

                </el-dialog>

            </div>


        </div>

    </div>

</div>




</body>

<!-- 引入组件库 -->


<script>
    var vue = new Vue({
        el: '#app',
        data:{
            username:"",
            password:"",
            dataList: [],//当前页要展示的列表数据
            dialogFormVisible: false,//添加表单是否可见
            dialogFormVisible4Edit:false,//编辑表单是否可见
            formData: {},
            world: {},
            rules: {//校验规则
                type: [{ required: true, message: '账户名', trigger: 'blur' }],
                name: [{ required: true, message: '密码', trigger: 'blur' }]
            },
            pagination: {//分页相关模型数据
                "currentPage": 1,//当前页码
                "pageSize":10,//每页显示的记录数
                "total":0,//总记录数
                "type":"",
            }

        },

        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            //初始化调用查询全部数据
            this.getAll();
        },

        methods: {
            // 列表
            getAll() {
               axios.get("/").then((res)=>{
                   // console.log(res.data)
                   this.dataList=res.data.data;
               })
            },

            //弹出添加窗口
            handleCreate() {
                this.dialogFormVisible =true;
                this.resetForm()
            },

            //重置表单
            resetForm() {
                this.formData={};
            },

            //添加
            handleAdd () {
                axios.post("/inserte",this.formData).then((res)=>{
                    // 判断当前操作是否成功
                    if(res.data.flag){
                        // 1.关闭弹层
                        this.dialogFormVisible =false;
                        this.$message.success(res.data.msg);
                    }
                    else {
                        this.$message.success(res.data.msg);
                    }
                    //是否成功或者不成功都会刷新
                }).finally(()=>{
                    // 2. 重新加载数据
                    this.getAll();
                })
            },

            //取消
            cancel(){
                this.dialogFormVisible =false;
                this.dialogFormVisible4Edit =false;
                this.$message.info("当前操作取消")
            },
            // 删除
            handleDelete(row) {
                // console.log(row);

                this.$confirm("此操作永久删除当前信息,是否继续?","提示:",{type:"info"}).then(()=>{
                    axios.delete("/delete/"+row.id).then((res)=>{
                        if(res.data.flag){
                            this.$message.success("删除成功");
                        }
                        else {
                            this.$message.error("删除失败");
                        }
                    }).finally(()=>{
                        // 2. 重新加载数据
                        this.getAll();
                    })
                }).catch(()=>{
                    this.$message.info("取消操作")
                })
            },

            //弹出编辑窗口
            handleUpdate(row) {
                axios.get("/update/"+row.id).then((res)=>{
                    if(res.data.flag && res.data.data != null){
                        this.dialogFormVisible4Edit=true;
                        this.formData =res.data;
                        console.log(this.formData)
                    }else {
                        this.$message.error("数据同步失败，自动刷新");
                    }
                }).finally(()=>{
                    // 2. 重新加载数据
                    this.getAll();
                })
            },

            //修改
            handleEdit() {
                console.log(this.formData)
                axios.post("/update",this.formData).then((res)=>{
                    if(res.data.flag){
                        //1.关闭弹层
                        this.dialogFormVisible4Edit = false;
                        this.$message.success("修改成功");
                    }else {
                        this.$message.error("修改失败");
                    }
                }).finally(()=>{
                    this.getAll();
                })
            },
            //条件查询
        }
    })
</script>

</html>